package com.xingongchang.baolebei.fragment;

import java.util.ArrayList;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xingongchang.baolebei.ImageDisplay;
import com.xingongchang.baolebei.R;
import com.xingongchang.baolebei.protocol.User_tan;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

public class FourAdapter extends BaseAdapter {
	
	public ArrayList<User_tan> list = new ArrayList<User_tan>();
	private LayoutInflater inflater;
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	DisplayImageOptions options;
	Context mcontext;
	public FourAdapter(Context context, ArrayList<User_tan> list, DisplayImageOptions options) {
		this.list = list;
		inflater = LayoutInflater.from(context);
		ImageView iamgeView = new ImageView(context);
		iamgeView.setScaleType(ScaleType.CENTER_CROP);
		this.mcontext=context;
		this.options = options;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		ViewHolder holder;
		if(arg1==null){
			holder=new ViewHolder();
			arg1 = inflater.inflate(R.layout.formlayout, null);
			holder.topic_img=(ImageView) arg1.findViewById(R.id.profile_photo);
			holder.topic_tag= (TextView) arg1.findViewById(R.id.good_title);
			holder.topic_title=(TextView) arg1.findViewById(R.id.good_desc);
			arg1.setTag(holder);
		} else {
			holder = (ViewHolder) arg1.getTag();
		}
		User_tan topic = list.get(arg0);
		holder.topic_tag.setText(topic.cat_name);
		holder.topic_title.setText(topic.cat_desc);
		if(topic.thumb.equals("")){
			holder.topic_img.setImageResource(R.drawable.default_image);
		}else{
			imageLoader.displayImage(topic.thumb, holder.topic_img, options);
		}
		return arg1;
	}
	class ViewHolder {
		private ImageView topic_img;
		private TextView topic_tag;
		private TextView topic_title;

	}


}
